<div class="setting com_width">
    <?php include PROJECT_PATH . 'Application/View/menu.tpl.php';?>
    <div class="menu_head"></div>
    <div class="right">
        <div class="useradd">
            <div class="info">
                <span class="title">用户名:</span>
                <input id="username" class="username text" type="text" value="" />
            </div>
            <div class="info">
                <span class="title title_auth">角色:</span>
                <select id="userlevel" class="userlevel text">
                    <option value="-1">请选择角色</option>
                    <?php foreach($levelinfo as $key=>$value){?>
                    <option value="<?=$key?>"><?=$value['name']?></option>
                    <?php }?>
                </select>
            </div>
            <div class="errmsg" id="errmsg"></div>
            <div class="info">
                <input id="useradd" class="btn btn_input"type="button" value="添 加">
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $("#username").focus();
    $("#useradd").click(function (){
        username = $("#username").val();
        userlevel = $("#userlevel").val();
        $("#errmsg").text("");
        $.ajax({
              url: "http://<?=HOST?>/user/doAdd",
              cache: false,
              timeout:10000,
              type: "POST",
              data: {
                  username:username,
                  userlevel:userlevel
              },
              dataType: "json",
              beforeSend: function() {
                  disableHTML(true, '请稍等，处理中……', true);
              },
              success: function(data) {
                  if(data.errCode != 0){
                    disableHTML(true, data.errMsg, false);
                        setTimeout(disableHTML,2000);
                        $("#errmsg").text(data.errMsg);
                        $("#username").focus();
                  }else{
                    disableHTML(true, '处理成功，跳转中……', true);
                    setTimeout("location.href = 'http://<?=HOST?>/user/list'",1000);
                  }
              },
              error:function(){
                disableHTML(true, "请求出错，请重试或联系管理员", false);
                setTimeout(disableHTML,2000);
            }
            });
    });
</script>
